/*
 *  跳跃 其实严格来说不算dp问题
 * */

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;
int f[N][N];
int n, m;
const int dir[9][2] = {{0, -1}, {0, -2}, {0, -3}, {-1, 0}, {-1, -1}, {-1, -2}, {-2, 0}, {-2, -1},
                       {-3, 0}};

int main() {
    ios::sync_with_stdio(false);

    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin >> f[i][j];

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (i == 1 && j == 1) continue;
            int max_value = -10001;
            for (int k = 0; k < 9; ++k) {
                int xx = i + dir[k][0], yy = j + dir[k][1];
                if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
                max_value = max(f[xx][yy], max_value);
            }
            f[i][j] += max_value;
        }
    }

    cout << f[n][m];
    return 0;
}